package com.tangula.voicenote.db

import com.tangula.android.orm.BaseDataBaseHelper
import com.tangula.android.orm.Entity
import com.tangula.voicenote.entity.NoticeEntity
import org.apache.commons.lang3.StringUtils
import java.util.*

class NoteDbHelper : BaseDataBaseHelper<NoticeEntity>() {

    fun createOrSaveNote(entity: NoticeEntity): NoticeEntity {
        if (StringUtils.isBlank(entity.id)) {
            entity.id = UUID.randomUUID().toString()
        }
        entity.updateTm = System.currentTimeMillis()
        return save(entity)!!
    }

    fun listAllNotes(): List<Entity<String>> {
        return byCondition("", arrayOf<String>(), "", "", "updateTm")
    }

    fun removeNote(entity: NoticeEntity) {
        val res = getDatabase()?.delete("T_NOTICE", "id=?", arrayOf(entity.id))
    }

}